using System;
using Clandestine.Graphics.Window;
using Qyoto;
//using OpenTK; // ARGH
using Clandestine.Base;

namespace Shlick
{
	public class GLWidgetWindowHandler : WindowHandler
	{
		bool on = false;
		private const bool DebugMCCRC = false;
		
		public GLWidget GLWidget { get; private set; }
	
        public GLWidgetWindowHandler(GLWidget glWidget)
        {
        	this.GLWidget = glWidget;
        }
		
		private void funDebug(bool b)
		{
			if (!DebugMCCRC)
				return;
			
			Log.hacks = true;
			Log.w("DEBUG: " + (b ? "MakeContextCurrent" : "ReleaseContext") + " called here!");
			Log.hacks = false;
		}
        
        public override void MakeContextCurrent()
        {
			funDebug(true);
			if (on)
				throw new Exception("MakeContextCurrent/ReleaseContext not paired correctly!");
			
            //this.GLWidget.MakeCurrent();
			this.GLWidget.Context().MakeCurrent();
			on = true;
			
        }

        public override void ReleaseContext()
        {
			funDebug(false);
			if (!on)
				throw new Exception("MakeContextCurrent/ReleaseContext not paired correctly!");
			
            this.GLWidget.Context().DoneCurrent();
			//this.GLWidget.DoneCurrent();
			on = false;
        }

        public override void ProcessEvents()
        {
            
        }

        public override void SwapBuffers()
        {
            this.GLWidget.SwapBuffers();
        }

        public override object Keyboard
        {
            get { throw new NotImplementedException(); }
        }

        public override object Mouse
        {
            get { throw new NotImplementedException(); }
        }
	}
}

